package com.qmzy.lab05.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.qmzy.lab05.entity.Account;
import com.qmzy.lab05.entity.Yqdk;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.time.LocalDate;

@Service
public class DbService {

    @Autowired
    private IAccountService service;

    @Autowired
    private IYqdkService yqdkService;

    @Scheduled(cron = "0 0 0 * * *")
    public void updateAccount(){
        UpdateWrapper<Account> updateWrapper = new UpdateWrapper<Account>().set("clock",0);
        service.update(updateWrapper);
    }

    @Scheduled(cron = "0 0 0 1/14 * ?")
    public  void deletedate(){
        LocalDate localDate = LocalDate.now();
        LocalDate date = LocalDate.of(localDate.getYear(),localDate.getMonthValue(),localDate.getDayOfMonth() - 14);
        QueryWrapper<Yqdk> queryWrapper = new QueryWrapper<Yqdk>().le("full_date",date.toString());
        yqdkService.remove(queryWrapper);
    }
}
